var fetch3 = function(pageIndex){
  //frequentUseInNight 夜间频繁使用/短期异常活动-->

  $.ajax({
    type: 'GET',
    url: houseInfo.ajaxUrl[2].page(pageIndex,10),
    beforeSend: function (xhr) {
      xhr.setRequestHeader('Authorization', tokenPgAuth);
      xhr.setRequestHeader('Accept-Profile', 'api-ailock-analysis-v1');
    }
  }).done(function (response,type,request1) {
    response = response || [];
    let len = response.length;
    if(len > 200){
      $('#' + houseInfo.totalDomId[2] + 2).text('200+')
      fetch3Again(1)
    }else{
      houseInfo.total[2] = len
      $('.' + houseInfo.totalDomId[2] + 1).text(houseInfo.total[2])
      $('#' + houseInfo.totalDomId[2] + 2).text(houseInfo.total[2])
      for(var i=0;i<(len + 10 - 1) / 10 -1 ;i++){
        houseInfo.cacheList['frequentUseInNightTable'][i*10] = response.slice(i*10, i*10 + 10 )
      }
      var options = {
        bDestroy:true,
        searching: false,
        bPaginate: true ,//表格分页
        bSort: false,
        bLengthMenu: false,
        bInfo: false,
        pageLength:10, // 每页显示数量
        bAutoWidth: false,
        bLengthChange: false,
        bProcessing: true,
        data: response,
        columns: [
          {
            data: "simpleaddr",
            bSortable: false,
            align: 'left',
            render: function (data, type, full, meta) {
              if (!data) data = '--';
              return data
            }
          },
          {
            data: "housenumber",
            class: 'digit ta',
            bSortable: false,
            render: function (data, type, full, meta) {
              if (!data) data = '--';
              return data
            }
          },
          {
            data: "stats_per_lock_for_active_formal",   //钥匙数量
            width: '200',
            align: 'left',
            className: 'ta',
            bSortable: false,
            render: function (data, type, full, meta) {
              return full.stats_per_lock_for_active_formal.tally_keys ? full.stats_per_lock_for_active_formal.tally_keys: '--'
            }
          },
          {
            data: "tally_per_lock_event_for_active_formal_today",   //当日开门总数
            align: 'left',
            className: 'ta',
            bSortable: false,
            render: function (data, type, full, meta) {
              if (!data) data = '--';
              return data
            }
          }
        ],
        fnInitComplete: function(settings){
          houseInfo.bindEvent[2]()
        }
      };
      houseInfo.tables[2] = $('.frequentUseInNightTable').dataTable(options);
    }
  })



};

// 如果总条数小于200条，则不用请求该接口
var fetch3Again = function(pageIndex){
    //frequentUseInNight 夜间频繁使用/短期异常活动-->
    $.ajax({
      type: 'GET',
      url: houseInfo.ajaxUrl[2].page(pageIndex,10),
      beforeSend: function (xhr) {
        xhr.setRequestHeader('Authorization', tokenPgAuth);
        xhr.setRequestHeader('Accept-Profile', 'api-ailock-analysis-v1');
        xhr.setRequestHeader('Prefer', 'count=exact');
      }
    }).done(function (response,type,request1) {
      //一房多人的总数 总数使用在slider里面一个 图标一个 分页处三个地方
      houseInfo.total[2] = pgApiUtils.getTotal(request1); //总数
      $('.' + houseInfo.totalDomId[2] + 1).text(houseInfo.total[2])
      $('#' + houseInfo.totalDomId[2] + 2).text(houseInfo.total[2])
      var options = {
        bDestroy:true,
        searching: false,
        bPaginate: true ,//表格分页
        bSort: false,
        bLengthMenu: false,
        bInfo: false,
        pageLength:10, // 每页显示数量
        bAutoWidth: false,
        bLengthChange: false,
        bProcessing: true,
        data: response,
        pgAiDisplayLength:houseInfo.total[2],
        fnPageChange:function(settings){
          changePage(settings,'.frequentUseInNightTable','nothing')
        },
        columns: [
          {
            data: "simpleaddr",
            bSortable: false,
            align: 'left',
            render: function (data, type, full, meta) {
              if (!data) data = '--';
              return data
            }
          },
          {
            data: "housenumber",
            class: 'digit ta',
            bSortable: false,
            render: function (data, type, full, meta) {
              if (!data) data = '--';
              return data
            }
          },
          {
            data: "stats_per_lock_for_active_formal",   //钥匙数量
            width: '200',
            align: 'left',
            className: 'ta',
            bSortable: false,
            render: function (data, type, full, meta) {
              return full.stats_per_lock_for_active_formal.tally_keys ? full.stats_per_lock_for_active_formal.tally_keys: '--'
            }
          },
          {
            data: "tally_per_lock_event_for_active_formal_today",   //当日开门总数
            align: 'left',
            className: 'ta',
            bSortable: false,
            render: function (data, type, full, meta) {
              if (!data) data = '--';
              return data
            }
          }
        ],
        fnInitComplete: function(settings){
          houseInfo.bindEvent[2]()
        }
      };


      houseInfo.tables[2] = $('.frequentUseInNightTable').dataTable(options);


    })

  };


houseInfo.bindEvent[2] = function () {
    $(".frequentUseInNightTable").on("click","tr",function(){//给tr或者td添加click事件
      var data=houseInfo.tables[2].api().row(this).data();//获取值的对象数据
      console.log(data);
      getRenterListAndHouseMaster(data)
    //   $.ajax({
    //     type: 'GET',
    //     url:pgApiUtils(optimizedBaseUrl + requestApiUrl.LandlordInfo)
    //       .setRequestUrl('select=house(housenumber,operation(operator_name,operator_mobile,simpleaddr,n_house))&')
    //       .eqVal('lockid:'+data.lockid)
    //       .order('lockid'),
    //     beforeSend: function (xhr) {
    //       xhr.setRequestHeader('Authorization', tokenPgAuth);
    //       xhr.setRequestHeader('Accept-Profile', 'api-ailock-analysis-v1');
    //     }
    //   }).done((res)=>{
    //     console.log('fanhuizhi',res)
    //   }).fail((err)=>{
    //     console.log(err)
    //   })
    //   $.ajax({
    //     type: 'GET',
    //     url:pgApiUtils(optimizedBaseUrl + requestApiUrl.LandlordInfo2)
    //       .setRequestUrl('select=n_house&')
    //       .eqVal('operator_name:'+data.operator_name,'operator_mobile:'+data.operator_mobile),

    //     beforeSend: function (xhr) {
    //       xhr.setRequestHeader('Authorization', tokenPgAuth);
    //       xhr.setRequestHeader('Accept-Profile', 'api-ailock-analysis-v1');
    //     }
    //   }).done((res)=>{
    //     console.log('fanhuizhi',res)
    //   }).fail((err)=>{
    //     console.log(err)
    //   })

    })
}
